package com.zhuss.util;

import java.io.File;
import java.io.IOException;

import net.coobird.thumbnailator.Thumbnails;

import com.zhuss.exception.WpsException;

public class ForceSmallUtil {
	
	public static final String name = "昆山市体育馆";
	
	public static String key = "昆山市体育馆.jpg";
	
	public static final String small = "forcesmall/";
	
	
	
	public static int forceSmallHistory() throws WpsException {
		File forcesmall1 = new File("/home/file/wpsFile/upload/forcesmall1/");
		File[] files = forcesmall1.listFiles();
		int i = 0;
		for (File file : files) {
			i ++;
			
			
			
			System.out.println(i);
			String fileName = file.getName();
			String fileFullName = file.getAbsolutePath();
			System.out.println(fileName);
			
			File file2 = new File("/home/file/wpsFile/upload/forcesmall/" + fileName);			
			if (!file2.exists()) {
				try {
					Thumbnails.of(fileFullName)   
					.size(100, 100)
					.toFile("/home/file/wpsFile/upload/forcesmall/" + fileName);
				} catch (IOException e) {
					e.printStackTrace();
					// throw new WpsException(ExceptionCode.生成缩略图失败);
				}
			}
			
		}
		
		System.out.println("length: ====================" + files.length);
		return i;
		
	}
	
	
	public static void forceSmall(String path, String key, String smallKey) throws WpsException {
		try {
			Thumbnails.of(path + key)   
			.size(100, 100)
			.toFile(path + small + smallKey);
		} catch (IOException e) {
			e.printStackTrace();
			// throw new WpsException(ExceptionCode.生成缩略图失败);
		}
	}
	
	
	
	
	
	
	public static void main(String[] args) throws IOException, WpsException {
		
		int i = forceSmallHistory();
		
		System.out.println(i);
		
		/*Thumbnails.of("C:\\Users\\Administrator\\Desktop\\1\\" + name + ".jpg")   
        .size(100, 100)
        .toFile("C:\\Users\\Administrator\\Desktop\\1\\" + PwdUtil.md5(name) +".jpg");
		
		String smallKey = key.substring(0, key.indexOf(".")) + "-1" + key.substring(key.indexOf("."));
		
		System.out.println(key);
		System.out.println(smallKey);*/
	}

}
